//
//  YSInfoHepSelfHeader.m
//  YaSha-iOS
//
//  Created by 蘑菇加 on 2017/12/8.
//  Copyright © 2017年 亚厦装饰股份有限公司. All rights reserved.
//

#import "YSHRInfoHepSelfHeader.h"
@interface YSHRInfoHepSelfHeader()
@property (nonatomic,strong) UILabel *nameLb;
@property (nonatomic,strong) UILabel *workNumLb;
@property (nonatomic,strong) UILabel *briefLb;
@end
@implementation YSHRInfoHepSelfHeader
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}
- (void)initUI{
    _headImageView = [[UIImageView alloc]init];
    _headImageView.contentMode = UIViewContentModeScaleAspectFill;
    _headImageView.layer.cornerRadius = 73*kWidthScale*0.5;
    _headImageView.layer.masksToBounds = YES;
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headImageDidClick)];
    _headImageView.userInteractionEnabled = YES;
    [_headImageView addGestureRecognizer:gesture];
    [self addSubview:_headImageView];
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(22*kHeightScale);
        make.width.height.mas_equalTo(73*kWidthScale);
    }];
    
    _nameLb = [[UILabel alloc]init];
    _nameLb.text = @"    ";
    _nameLb.textColor = kGrayColor(51);
    _nameLb.font = [UIFont systemFontOfSize:16];
    [self addSubview:_nameLb];
    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(_headImageView.mas_bottom).mas_equalTo(18*kHeightScale);
    }];
    
    _workNumLb = [[UILabel alloc]init];
    _workNumLb.textColor = kUIColor(93, 100, 110, 1);
    _workNumLb.font = [UIFont systemFontOfSize:15];
    [self addSubview:_workNumLb];
    [_workNumLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(_nameLb.mas_bottom).mas_equalTo(10*kHeightScale);
    }];
    
    _briefLb = [[UILabel alloc]init];
    _briefLb.textColor = kUIColor(93, 100, 110, 1);
    _briefLb.font = [UIFont systemFontOfSize:15];
    [self addSubview:_briefLb];
    [_briefLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(_workNumLb.mas_bottom).mas_equalTo(10*kHeightScale);
    }];
    
    
    

}
- (void)setInfoModel:(YSPersonalInformationModel *)infoModel
{
    _infoModel = infoModel;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:infoModel.headImg] placeholderImage:[UIImage imageNamed:@"头像"]];
    self.nameLb.text = infoModel.name;
    self.workNumLb.text = infoModel.no;
    
    NSString *dept = infoModel.deptName;
    NSString *job = infoModel.jobStation;
    if (job.length&&dept.length) {
        NSString *brief = [NSString stringWithFormat:@"%@ | %@",dept,job];
        NSMutableAttributedString *attiStr = [[NSMutableAttributedString alloc]initWithString:brief];
        [attiStr addAttributes:@{NSForegroundColorAttributeName:kGrayColor(204)} range: [brief rangeOfString:@"|"]];
        self.briefLb.attributedText = attiStr;
    }else{
        self.briefLb.text = [NSString stringWithFormat:@"%@%@",dept,job];
    }
    
}
- (void)headImageDidClick {
    if ([self.delegate respondsToSelector:@selector(hrInfoHepSelfHeaderImageViewDidClick:)]) {
        [self.delegate hrInfoHepSelfHeaderImageViewDidClick:self];
    }
}
@end
